package com.lanou.musicbox.adapter.onlinemusic;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.RecommendStation;
import com.lanou.musicbox.utils.VolleySingleton;

import java.util.ArrayList;

/**
 * Created by dllo on 15/10/31.
 */
public class RecommendstationAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<RecommendStation.ListEntity>data;
    private ImageLoader imageLoader;
    public  RecommendstationAdapter(Context context,ArrayList<RecommendStation.ListEntity>data){
        this.context=context;
        this.data=data;
        imageLoader= VolleySingleton.getInstance(context).getImageLoader();
    }
    @Override
    public int getCount() {
        return data!=null&&data.size()>0?data.size():0;
    }

    @Override
    public Object getItem(int position) {
        return data!=null&&data.size()>0?data.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold viewHold=null;
        //布局加载器加载布局
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.recommend_station_item,null);
            viewHold=new ViewHold();
            viewHold.station_name= (TextView) convertView.findViewById(R.id.station_name);
            viewHold.recommend_num= (TextView) convertView.findViewById(R.id.recommend_num);
            viewHold.station_pic= (ImageView) convertView.findViewById(R.id.station_pic);
            convertView.setTag(viewHold);
        }else{
            viewHold= (ViewHold) convertView.getTag();
        }
        RecommendStation.ListEntity recommendStation= (RecommendStation.ListEntity) getItem(position);
        viewHold.station_name.setText(recommendStation.getTitle());
        viewHold.recommend_num.setText(recommendStation.getDesc());
        ImageLoader.ImageListener imageListener=ImageLoader.getImageListener(viewHold.station_pic,R.mipmap.loading,R.mipmap.loading);
        imageLoader.get(recommendStation.getPic(),imageListener);
        return convertView;
    }

    class ViewHold{
        private ImageView station_pic;
        private TextView station_name;
        private TextView recommend_num;
    }
}
